package com.chenyaowei.web.controller.product.relation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.product.domain.CywProductAttrValue;
import com.chenyaowei.product.service.ICywProductAttrValueService;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.common.core.page.TableDataInfo;

/**
 * 商品基本属性Controller
 *
 * @author 陈耀威
 * @date 2023-11-24
 */
@RestController
@RequestMapping("/product/attrValue")
public class CywProductAttrValueController extends BaseController
{
    @Autowired
    private ICywProductAttrValueService cywProductAttrValueService;

    @PutMapping("/batch")
    public AjaxResult updateBatch(@RequestBody List<CywProductAttrValue> list)
    {
        return toAjax(cywProductAttrValueService.updateBatch(list));
    }

    @GetMapping("/list/{spuId}")
    public AjaxResult selectListBySpuId(@PathVariable("spuId") Long spuId)
    {
        List<CywProductAttrValue> list = cywProductAttrValueService.selectListBySpuId(spuId);
        return success(list);
    }

    /**
     * 查询商品基本属性列表
     */
    @PreAuthorize("@ss.hasPermi('product:attrValue:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywProductAttrValue cywProductAttrValue)
    {
        startPage();
        List<CywProductAttrValue> list = cywProductAttrValueService.selectCywProductAttrValueList(cywProductAttrValue);
        return getDataTable(list);
    }

    /**
     * 导出商品基本属性列表
     */
    @PreAuthorize("@ss.hasPermi('product:attrValue:export')")
    @Log(title = "商品基本属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywProductAttrValue cywProductAttrValue)
    {
        List<CywProductAttrValue> list = cywProductAttrValueService.selectCywProductAttrValueList(cywProductAttrValue);
        ExcelUtil<CywProductAttrValue> util = new ExcelUtil<CywProductAttrValue>(CywProductAttrValue.class);
        util.exportExcel(response, list, "商品基本属性数据");
    }

    /**
     * 获取商品基本属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:attrValue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cywProductAttrValueService.selectCywProductAttrValueById(id));
    }

    /**
     * 新增商品基本属性
     */
    @PreAuthorize("@ss.hasPermi('product:attrValue:add')")
    @Log(title = "商品基本属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CywProductAttrValue cywProductAttrValue)
    {
        return toAjax(cywProductAttrValueService.insertCywProductAttrValue(cywProductAttrValue));
    }

    /**
     * 修改商品基本属性
     */
    @PreAuthorize("@ss.hasPermi('product:attrValue:edit')")
    @Log(title = "商品基本属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywProductAttrValue cywProductAttrValue)
    {
        return toAjax(cywProductAttrValueService.updateCywProductAttrValue(cywProductAttrValue));
    }

    /**
     * 删除商品基本属性
     */
    @PreAuthorize("@ss.hasPermi('product:attrValue:remove')")
    @Log(title = "商品基本属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cywProductAttrValueService.deleteCywProductAttrValueByIds(ids));
    }
}
